/*************************************************************************
	> File Name: P1091.cpp
	> Author: yufangze
	> Mail: 2224590123@qq.com
	> Created Time: 2025-01-02 14:40:51
 ************************************************************************/

#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;

#define MAX_N 100

int f[MAX_N + 5];
int g[MAX_N + 5];
int val[MAX_N + 5];

int main() {
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> val[i];
        f[i] = 1;
        g[i] = 1;
    }
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j < i; j++)
        if (val[j] < val[i]) {
            f[i] = max(f[i], f[j] + 1);
        }
    }
    for (int i = n; i >= 1; i--) {
        for (int j = n; j > i; j--)
        if (val[j] < val[i]) {
            g[i] = max(g[i], g[j] + 1);
        }
    }
    int max_n = 0;
    for (int i = 1; i <= n; i++) {
        if (f[i] + g[i] - 1 > max_n) {
            max_n = f[i] + g[i] - 1;
        }
    }
    cout << n - max_n << endl;
    return 0;
}
